<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.workflow.jbpm.mgmt.*"%>
<%@ page import="com.gzgi.workflow.jbpm.mgmt.monitor.*"%>
<%@ include file="/pages/tm/header.jsp"%>

<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/scripts/ext/app/grid/grid-examples.css" />
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/scripts/ext/app/examples.css" />

<script language="javascript">

Ext.onReady(function(){

    var store = new Ext.data.Store({
       
        proxy: new Ext.data.HttpProxy({
            url: 'productList-json.jsp '
        }),
 
        reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'totalCount',
            id: 'productId',
            fields: [
				'x_rowNum',
                'productName', 'processName','productCode','manufacturer','description','statusCode','processInstanceId','statusName',
				{name: 'productDate', mapping: 'productDate'},
                {name: 'quantity', mapping: 'quantity', type:'int'},
				{name: 'price', mapping: 'price', type:'float'},
				{name: 'status', mapping: 'status'},
				{name: 'wfStatus', mapping: 'wfStatus'}
            ]
        })
    });

    function renderTopic(value, p, record){
        return String.format(
                '<b><a href="product.jsp?productId={1}&method=stateInstances" >{2}</a></b>',
                value,  record.id, record.data.productName);
    }

	function renderXYTopic(value, p, record){
        return String.format(
                '<b><a href="product.jsp?productId={1}&method=stateInstances" >{2}</a></b>',
                value,  record.id, record.data.x_rowNum);
    }

	function renderFunctionKey(value, p, record){
        return String.format(
                '<b><a href="<%=request.getContextPath()%>/pages/jbpm/jsp/task/task.jsp?method=stateInstances&processInstanceId={2}" target="_blank"><img src="<%=request.getContextPath()%>/pages/images/view.gif" border="0"  title="查看流程任务信息"></a></b>',
                value, record.id, record.data.processInstanceId);
    }
   
    var cm = new Ext.grid.ColumnModel([
	   {id: 'x_rowNum', header: '序号', dataIndex: 'x_rowNum', width: 60, align: 'left', renderer: renderXYTopic},
	   {
           id: 'productName', 
           header: "产品名称",
           dataIndex: 'productName',
           width: 120,
           renderer: renderTopic
        },{
           header: "产品编码",
           dataIndex: 'productCode',
           width: 120,
           align: 'left'
        },{
           header: "厂商",
           dataIndex: 'manufacturer',
           width: 120,
           align: 'left'
        },{
           header: "单价",
           dataIndex: 'price',
           width: 90,
           align: 'right'
        },{
           header: "数量",
           dataIndex: 'quantity',
           width: 90,
           align: 'right'
        },{
           id: 'productDate',
           header: "生产日期",
           dataIndex: 'productDate',
           width: 80,
		   align: 'center'
        },{
           id: 'statusName',
           header: "状态",
           dataIndex: 'statusName',
           width: 80,
		   align: 'left'
        },{
           id: 'functionKey',
           header: "功能键",
		   dataIndex: 'xx',
           width: 90,
		   align: 'center',
		   renderer: renderFunctionKey
        }]);

    cm.defaultSortable = true;

    var grid = new Ext.grid.GridPanel({
        el:'x-grid-data',
        width:<%=MessageProperties.getGridWidth()%>,
        height:<%=MessageProperties.getGridHeight()%>,
        title:'产品信息',
        store: store,
        cm: cm,
        collapsible: true,
		frame:true,
        animCollapse: false,
        trackMouseOver:true,
        loadMask: true,
	    tbar: [{
			 id:'edit-btn',
             text: '<span class="ext-button">新增</span>',
			 handler:editProduct
        } ],
        bbar: new Ext.PagingToolbar({
            pageSize: 25,
            store: store,
            displayInfo: true,
            displayMsg: '显示第 {0} 条到 {1} 条记录 总共 {2} 条',
            emptyMsg: "没有记录"
        })
    });

    grid.render();

    store.load({params:{start:0, limit:25}});

    function editProduct(){
		location.href="product.jsp";
	}
});

</script>
</head>
<body>

<div id="x-grid-data" class="x-grid-data"></div>

</div>

</body>